package com.plian.system.service.bt.loginfo;

import com.plian.Tools.pagedata.PageData;
import com.plian.system.config.exception.MyRuntimeException;
import com.plian.system.dao.bt.loginfo.LogInfoDao;
import com.plian.system.model.CommonCode;
import com.plian.system.model.ListResult;
import com.plian.system.model.ObjResult;
import com.plian.system.model.page.Page;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogInfoService  {
    @Autowired
    LogInfoDao logInfoDao;
    /**
     * logger属性.
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(LogInfoService.class);

    /**
     * 单据详情
     *
     * @param pd
     * @return
     */
    public ObjResult findbyid(PageData pd) {
        try {
            ObjResult objResult;
            PageData p = logInfoDao.findById(pd.getString("id"));
            objResult = new ObjResult(CommonCode.SUCCESS);
            objResult.setPageData(p);
            return objResult;
        } catch (Exception e) {
             LOGGER.error(ExceptionUtils.getStackTrace(e));
            throw new MyRuntimeException(new ObjResult(CommonCode.ERROR));
        }
    }

    /**
     * 查询列表
     *
     * @return
     */
    public ListResult list(PageData pd) {
        ListResult listResult;
        try {
            String keywords = pd.getString("keywords");
            if (null != keywords && !"".equals(keywords)) {
                pd.put("keywords", keywords.trim());
            }
            String requestTime = pd.getString("requestTime");
            if (null != requestTime && !"".equals(requestTime)) {
                pd.put("requestTime", requestTime);
            }
            Page page = new Page(true, pd);
            List<PageData> list = logInfoDao.list(page);
            listResult = new ListResult(CommonCode.SUCCESS);
            listResult.setList(list);
            listResult.setTotal(page.getTotal());
        } catch (Exception e) {
             LOGGER.error(ExceptionUtils.getStackTrace(e));
            listResult = new ListResult(CommonCode.ERROR);
        }
        return listResult;
    }
}